Skip to content

perf(stdune): use memchr for string searches - #16224

Open
rgrinberg wants to merge 5 commits into
ocaml:mainfrom
rgrinberg:push-vkwnznnmtpvv
Open

perf(stdune): use memchr for string searches#16224
rgrinberg wants to merge 5 commits into
ocaml:mainfrom
rgrinberg:push-vkwnznnmtpvv

Conversation

@rgrinberg

@rgrinberg rgrinberg commented Aug 27, 2026

Copy link
Copy Markdown
Member

Generalizes the spawn-specific NUL search from #16117 into a reusable forward string-search primitive backed by memchr. Stdune.String uses it for filename validation, splitting, spawn arguments, Unix path decomposition, and other forward character searches. Reverse searches and unrelated string transformations are deliberately left unchanged.

Follow-up commits use the shared search while scanning dune subst inputs and Unix path components, and add a bounded bytes search for the performance-sensitive artifact-substitution scanner. Lower-level standalone libraries that cannot depend on Stdune are also left unchanged.

@rgrinberg
rgrinberg force-pushed the push-vkwnznnmtpvv branch 2 times, most recently from 79a2f51 to 522f55e Compare August 28, 2026 09:26
rgrinberg added a commit that referenced this pull request Aug 28, 2026
Removes avoidable temporary allocations from frequently used string and
path helpers. It adds option-free internal character searches, uses them
in path decomposition, and constructs `Filename.concat` results in one
pass.

The dune-action-plugin path implementation now reuses the
allocation-conscious `Stdune.Filename.concat`. This preparatory change
was split from #16224 so allocation reductions can be reviewed
independently from the C-backed search optimization.

Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
@rgrinberg
rgrinberg force-pushed the push-vkwnznnmtpvv branch 9 times, most recently from 765e8f8 to f4e4c6c Compare August 29, 2026 18:42
Replace the pure unchecked forward string scan with a memchr primitive, use it for Stdune string searches, splitting, and validation, and generalize the spawn-specific NUL-byte search throughout Dune.

Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
Override the inherited scalar split_on_char implementation with Stdune.String.split so both public splitting APIs use the shared memchr-backed search.

Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
Skip spans without percent signs using the shared unchecked string search instead of examining every source byte in OCaml.

Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
Add a bounded memchr-backed Bytes search and use it to skip placeholder-free spans in the artifact substitution scanner.

Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
Scan Unix path components forward with the shared memchr primitive while retaining the multi-separator scanner on Windows.

Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant